/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csse3004.GD.PC;

//Includes
import csse3004.GD.DA.PollCreatorDA;
import csse3004.GD.Poll;
import java.util.ArrayList;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author Lewis Kelly 42007689
 */
@Controller
public class homeController{
    protected final Log logger = LogFactory.getLog(getClass());
    
    //Create instance of user
    private PollCreatorService pollCreatorService = new PollCreatorDA();
    
    //Used to get session attributes
    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView handleRequest(HttpSession session) throws Exception {

        ArrayList<Poll> pollList = new ArrayList<Poll>();
        int userID = Integer.parseInt((String)session.getAttribute("userID")); 
        pollList = pollCreatorService.getPolls(userID);
        
        //Return the home page
        return new ModelAndView("home", "polls", pollList);   

    }
  
}